package com.feishi.core.util.common.rbtree;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: caixq
 * Date: 2020-08-03
 * Time: 上午11:26
 */
public class Tree <T extends Comparable<T>>{
    private Node<T> root;
    public void insert(Node<T> node){
        if(root==null){
            root=node;
            return;
        }
        insert(node,root);
    }

    private void insert(Node<T> node, Node<T> root) {
        if(root.getData().compareTo(node.getData())>0){
            if(root.getRight()==null){
                root.setRight(node);
                orderNode(node);
                return;
            }
            insert(node,node.getRight());
        }else {
            if(root.getLeft()==null){
                root.setLeft(node);
                orderNode(node);
                return;
            }
            insert(node,node.getLeft());
        }
    }

    private void orderNode(Node<T> node) {
        if(Math.abs(node.getPowerLeft()-node.getPowerRight())>1){

        }










        if(node.getParent()!=null){
            if(node.getParent().getLeft()==node){
                node.setPowerLeft(node.getPower());
            }else {
                node.setPowerRight(node.getPower());
            }
            orderNode(node.getParent());
        }
    }

    private boolean setPower(Node<T> node) {

        return false;
    }
}
